package com.seek.springevent.activemq;

import jdk.nashorn.internal.runtime.options.Option;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTextMessage;

import javax.jms.*;
import javax.jms.MessageConsumer;
import java.util.Optional;

public class ActiveMQConsumer {
    public static void main(String[] args) {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin","admin","tcp://localhost:61616");
//        try (Connection connection = connectionFactory.createConnection();Session session =  connection.createSession(true,Session.AUTO_ACKNOWLEDGE);){
//            connection.start();
////            Destination destination = session.createQueue("seek.fail");
//            MessageConsumer consumer = session.createConsumer(new ActiveMQQueue("seek.fail"));
//            consumer.setMessageListener(new MessageListener() {
//                @Override
//                public void onMessage(Message message) {
//                    System.out.println("==================this is listener============");
//                    TextMessage textMessage = (TextMessage) message;
//                    try {
//                        System.out.println("=================={}====================" + textMessage.getText());
//                        session.commit();
//                    } catch (JMSException e) {
//                        e.printStackTrace();
//                    }
//
//                }
//            });
//
//            Thread.sleep(1000000);
////            Optional<TextMessage> message = Optional.of((TextMessage) consumer.receive());
////            message.get().acknowledge();
////            System.out.println("=================={}====================" + message.get().getText());
////            session.commit();
//        }catch (JMSException e){
//            e.printStackTrace();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
    }
}
